package jsyf.oa.web.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.entity.system.CompanyEntity;
import jsyf.oa.facade.system.GroupFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Administrator on 2017/12/30 0030.
 */
@Api(value = "分组接口", description = "分组接口")
@Controller
@RequestMapping("/group")
public class GroupController {
    @Resource
    private GroupFacade groupFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        String resultId = this.groupFacade.save(jsonData);
        String result = "";
        if ("".equals(resultId)) {
            result = BaseUtils.errorrRespond("服务器错误");
        } else {
            JSONObject obj = new JSONObject();
            obj.put("id", resultId);
            result = BaseUtils.succsessObjRespond(obj);
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    public void removeById(HttpServletResponse response, @RequestBody String jsonData) {
        String result = this.groupFacade.removeById(jsonData);
        ResponseUtils.putJsonResponse(response, result);
    }

    @RequestMapping(value = "/sort.json", method = RequestMethod.POST)
    public void sort(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        Boolean result = groupFacade.sort(jsonParam.getString("groupIds"));
        JSONObject objResult = new JSONObject();
        objResult.put("success", result);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }
}
